// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

// import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
// import '../static/font/iconfont.css'
Vue.config.productionTip = false

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

import peizhis from '@/assets/peizhi.js'
Vue.prototype.peizhis = peizhis

import {copy,go,down} from './assets/changyong.js'
Vue.prototype.copy = copy
Vue.prototype.go = go
Vue.prototype.downall = down

if(location.href.includes('localhost')){
  Vue.prototype.apis = '/apis'
}else{
  Vue.prototype.apis = ''
}
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

// axios.interceptors.request.use(
// 	config => {
// 		config.headers["token"] = localStorage.getItem("token");
// 		return config;
// 	},
// 	err => Promise.reject(err)
// );

axios.interceptors.response.use(
	response => {
		if (response.status === 200) {

			if(response.data.msg && response.data.msg.code != 0){
				if(response.data.msg.code == 401){
					router.push({path:'/login'})
				}else{
					return Promise.resolve(response);
				}
			}else{
				return Promise.resolve(response);
			}
		} else {
			return Promise.reject(response);
		}
	},
)

router.beforeEach((to, from, next) => {

	/* 路由发生变化修改页面title */
	// if (to.path == '/admindingdan') {
	// 	if (JSON.parse(localStorage.getItem('SHOP')).shop_id == 50481 || JSON.parse(localStorage.getItem(
	// 			'SHOP')).shop_id == 301655) {
	// 		next()
	// 	} else {
	// 		next('/login')
	// 	}
	// } else {
	// 	next()
	// }
	next()
})

//公共方法go
Vue.prototype.goid = function(url,id){
    router.push({
		path:url,
		query:{
			id:id
		}
	})
}




if (process.env.NODE_ENV === "development") {
	// Vue.prototype.url = 'http://b.china-orange.cn:81/api'
	Vue.prototype.url = '/apis'

}
if (process.env.NODE_ENV === "test") {
	// Vue.prototype.url = 'http://iot.91haoka.com/api2'
	Vue.prototype.url = 'http://91haoka.com:8080'

}
if (process.env.NODE_ENV === "production") {
	Vue.prototype.url = window.location.origin + '/api2'
}
/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
  store,
	components: {
		App
	},
	template: '<App/>'
})
